package com.ws.admin.donate.service.impl;

import cn.hutool.core.util.StrUtil;
import com.ws.admin.donate.entity.Donate;
import com.ws.admin.donate.mapper.DonateMapper;
import com.ws.admin.donate.service.IDonateService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ws.common.base.BaseUtils;
import com.ws.common.constant.BaseConstants;
import com.ws.system.user.entity.SystemUser;
import org.springframework.stereotype.Service;
import org.apache.ibatis.annotations.Param;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;

import java.util.HashMap;
import java.util.List;
import com.ws.common.utils.PageUtils;

/**
 * <p>
 * 捐赠信息表 服务实现类
 * </p>
 *
 * @author weifucheng
 * @since 2019-11-22
 */
@Service
public class DonateServiceImpl extends ServiceImpl<DonateMapper, Donate> implements IDonateService {

    @Override
    public Page<Donate> list(Donate donate, Integer current, Integer size) {
        Page<Donate> page= PageUtils.newPage(current, size);
        page.setRecords(baseMapper.listByParam(page,donate));
        return page;
    }

    @Override
    public Boolean save(Donate donate, SystemUser loginUser) {
        BaseUtils.setDefault(donate);
        if( StrUtil.isEmpty(donate.getAuditResult()) ){
            donate.setAuditResult(BaseConstants.AUDIT_RESULT_PENGDING);
        }
        if(StrUtil.isEmpty(donate.getDonatorId())){
            donate.setDonatorId(loginUser.getId());
        }
        return this.saveOrUpdate(donate);
    }

    @Override
    public Donate readByMap(HashMap map) {
        return baseMapper.readByMap(map);
    }

    @Override
    public Page<Donate> listRank(Donate donate,Integer current, Integer size) {
        Page<Donate> page= PageUtils.newPage(current, size);
        page.setRecords(baseMapper.listRank(page,donate));
        return page;
    }
}
